import DefineOptions from 'unplugin-vue-define-options/vite'
import { resolve } from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'


// https://vitejs.dev/config/
export default defineConfig({
  server: {
    proxy: {
      '/api': {
        target: 'https://test.anmeirui.top',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => {
          return path.replace(/^\/api\/backend/, '/api/backend')
        },
      },
    },
  },
  base: "./",
  plugins: [vue(), vueJsx({
    include: [/\.jsx$/, /\.tsx$/],
  }), DefineOptions()],
  resolve: {
    alias: [
      {
        find: '@',
        replacement: resolve(process.cwd(), '.', 'src') + '/',
      },
    ],
  },
  build: {
    // outDir: 'lib',
    lib: {
      entry: resolve(process.cwd(), '.', 'src/test.vue'),
      name: 'BlocksuitePlugin',
      fileName: 'test',
      formats: ['es'],
    },
    rollupOptions: {
      external: ['vue'],
      output: {
        globals: {
          vue: 'Vue',
        },
      }
    },
    // sourcemap: true
  }
})
